<template>
  <WindowDialog
    v-model="showDialog"
    title="Account Deletion"
    :description="dialogDescription"
    :icon="dialogIcon"
    icon-color="primary"
    @close="showDialog = false"
  >
    <v-card-text class="pa-6">
      <div v-if="isCommunity">
        In Community instances, user accounts can only be deleted via the CLI.
        For detailed instructions on user management, please refer to our
        <a
          href="https://docs.shellhub.io/self-hosted/administration#delete-a-user"
          target="_blank"
          rel="noopener noreferrer"
          class="text-primary"
          data-test="docs-link"
        >
          administration documentation
          <v-icon
            size="16"
            class="ml-1"
            icon="mdi-open-in-new"
          />
        </a>.

        <div>
          <p class="text-subtitle-2 mt-4 mb-2">
            Run this command to delete your account:
          </p>
          <CopyCommandField :command="deleteCommand" />
        </div>
      </div>

      <div v-else>
        <span>
          In Enterprise instances, user accounts can only be deleted via the Admin Console.
          Please access your
          <a
            class="font-weight-medium text-primary"
            href="/admin/users"
            target="_blank"
            rel="noopener noreferrer"
          >Admin Console</a>
          or contact your system administrator for assistance.
        </span>
      </div>
    </v-card-text>

    <template #footer>
      <v-spacer />
      <v-btn
        variant="text"
        data-test="close-btn"
        @click="showDialog = false"
      >
        Close
      </v-btn>
    </template>
  </WindowDialog>
</template>

<script setup lang="ts">
import WindowDialog from "@/components/Dialogs/WindowDialog.vue";
import CopyCommandField from "@/components/CopyCommandField.vue";
import useAuthStore from "@/store/modules/auth";
import { envVariables } from "@/envVariables";

const showDialog = defineModel<boolean>({ required: true });
const { username } = useAuthStore();
const { isCommunity } = envVariables;
const deleteCommand = `./bin/cli user delete ${username}`;
const dialogDescription = isCommunity ? "CLI Required" : "Admin Console Required";
const dialogIcon = isCommunity ? "mdi-console" : "mdi-shield-account";
</script>
